package com.daykw.ip.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class Const {

	@Autowired
	private Environment environment;

	public static final String SESSION_USER = "sessionUser";

	public static int ARTICLE_THREAD;

	public static int FIAL_400 = 400;
	public static int FIAL_500 = 500;
	public static int FIAL = 999;
	public static int SUC = 200;

	public static boolean isproxy = true;

	public static String Redis_IP;
	public static Integer Redis_PORT;

	public static ThreadPoolExecutor pool = null;

	//public static String IP_Kuaidaili = "http://ent.kuaidaili.com/api/getproxy/?orderid=931635759638898&num=500&b_pcchrome=1&b_pcie=1&b_pcff=1&protocol=1&method=1&an_an=1&an_ha=1&sp1=1&sp2=1&format=json&sep=1";
	//public static String IP_TYDAILI = "http://http-api.taiyangruanjian.com/getip?num=200&type=2&pro=&city=0&yys=0&port=1&pack=10860&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1&regions=";
	public static String IP_HCT = "http://2018011221001004600277321401.standard.hutoudaili.com/?num=1500";
	public static String IP_HUOJIAN = "http://vip.httpdaili.com/api.asp?ddbh=1986&old=&noinfo=true&sl=1500";
	//public static String IP_WNDAI = "http://www.wndaili.cn/api/?key=20180113200228663&getnum=1500&area=1&formats=2";
	public static String MDB_IP = "49.4.70.26";
	public static String MDB_DB = "xhs";
	public static Integer MDB_PORT = 27017;
	public static String MDB_USER = "xhs";
	public static String MDB_PWD = "admin123";
	@PostConstruct
	public void doStart() {

		Const.Redis_IP = environment.getProperty("redis.ip", String.class);
		Const.Redis_PORT = environment.getProperty("redis.port", Integer.class);

	}

	public static ExecutorService getKeyThreadPool(int thread) {

		if (pool == null) {
			pool = new ThreadPoolExecutor(thread, thread, 0L, TimeUnit.MILLISECONDS,
					new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.DiscardPolicy());
		}
		return pool;
	}
}
